﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HotelManagement.DAO;
using HotelManagement.DTO;

namespace HotelManagement.BLO
{
    class CustomerTypeBLO
    {
        private CustomerTypeDAO dao;

        public CustomerTypeBLO()
        {
            dao = new CustomerTypeDAO();
        }

        public DataTable Select()
        {
            return this.dao.Select();
        }

        public bool Insert(CustomerTypeDTO cusType)
        {
            return this.dao.Insert(cusType);
        }

        public bool Update(CustomerTypeDTO cusType)
        {
            return this.dao.Update(cusType);
        }
        public bool Delete(CustomerTypeDTO cusType)
        {
            return this.dao.Delete(cusType);
        }
        public int GetIDFromName(string pName)
        {
            if (pName=="")
            {
                return 0;
            }
            DataTable tbl = this.Select();

            foreach (DataRow r in tbl.Rows)
            {
                if (pName==r["TypeName"].ToString())
                {
                    return int.Parse(r["CusTypeID"].ToString());
                }
            }
            return 0;
        }

        public string GetNameFromID(int pID)
        {
            if (pID < 1)
            {
                return "";
            }
            DataTable tbl = this.Select();

            foreach (DataRow r in tbl.Rows)
            {
                if (pID == int.Parse(r["CusTypeID"].ToString()))
                {
                    return r["TypeName"].ToString();
                }
            }
            return "";
        }
    }
}
